package edu.spec.xhd.recyclerview;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

import edu.spec.xhd.R;

public class ActivityRecyclerView extends AppCompatActivity {

    private List<Fruit> fruitList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_view);
        initFruitList();
        FruitAdapter fa = new FruitAdapter(fruitList);
        LinearLayoutManager llm = new LinearLayoutManager(this);
        RecyclerView rv = findViewById(R.id.rv_fruit);
        rv.setLayoutManager(llm);
        rv.setAdapter(fa);
    }

    private void initFruitList(){
        fruitList = new ArrayList<>();
        Fruit apple = new Fruit("apple", R.drawable.apple);
        Fruit banana = new Fruit("banana", R.drawable.banana);
        Fruit blackberry = new Fruit("blackberry", R.drawable.blackberry);
        Fruit cherries = new Fruit("cherries", R.drawable.cherries);
        Fruit coconut = new Fruit("coconut", R.drawable.coconut);
        Fruit grapes = new Fruit("grapes", R.drawable.grapes);
        Fruit kiwi = new Fruit("kiwi", R.drawable.kiwi);
        Fruit lemon = new Fruit("lemon", R.drawable.lemon);
        Fruit peach = new Fruit("peach", R.drawable.peach);
        Fruit strawberry = new Fruit("strawberry", R.drawable.strawberry);
        Fruit watermelon = new Fruit("watermelon", R.drawable.watermelon);
        fruitList.add(apple);
        fruitList.add(banana);
        fruitList.add(blackberry);
        fruitList.add(cherries);
        fruitList.add(coconut);
        fruitList.add(grapes);
        fruitList.add(kiwi);
        fruitList.add(lemon);
        fruitList.add(peach);
        fruitList.add(strawberry);
        fruitList.add(watermelon);
    }

}
